﻿using CustomPlayerEffects;
using PlayerRoles;
using PluginAPI.Core;
using PluginAPI.Core.Attributes;
using PluginAPI.Enums;
using PluginAPI.Events;
using RoleCustom.Main;
using Utils;



namespace RoleCustom.Event
{
    public class SCP939Event
    {
        [PluginEvent(ServerEventType.PlayerDamage)]
        public void OnPlayerDamage(PlayerDamageEvent ev)
        {
            if (ev == null) return;
            if (ev.Player == null) return;
            if (ev.Player.Role != RoleTypeId.Scp939) return;

            try
            {
                if (ev.Target == null) return;

                if (ev.Target.Health >= 50)
                {
                    return;
                }

                ev.Target.Heal(7f);
                ev.Target.ReferenceHub.playerEffectsController.ChangeState<SeveredHands>(1, 0.7f, false);       
            }
            catch
            {

            }
        }


        [PluginEvent(ServerEventType.PlayerSpawn)]
        public void OnPlayerSpawn(PlayerSpawnEvent ev)
        {
            if (ev.Player.Role != PlayerRoles.RoleTypeId.Scp939) return;

            TimeCoroutine.Delay(0.5f, () =>
            {
                PlayerUtils.SetHP(ev.Player,
                    CodeLoad.Singleton.Config.SCP939Event.Health,
                    CodeLoad.Singleton.Config.SCP939Event.Health);

                PlayerUtils.SetAP(ev.Player,
                    CodeLoad.Singleton.Config.SCP939Event.AHealth,
                    CodeLoad.Singleton.Config.SCP939Event.AHealth);

                if (Round.IsLocked) return;
            });
        }
    }
}
